package com.example.test_1;

import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;


/** 单选框  */
public class demoRadioButton extends AppCompatActivity {


    private RadioGroup rgCity;
    private TextView tvcity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo_radio_button);

        rgCity = findViewById(R.id.rg_city);
        tvcity = findViewById(R.id.tv_city);

        //设置一个监听，监听选中setOncheckedChangeListener
        rgCity.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (R.id.rb_beijing ==i){
                    tvcity.setText("北京");
                    Toast.makeText(demoRadioButton.this, "casca", Toast.LENGTH_SHORT).show();
                }
                if (R.id.rb_chengdu ==i){
                    tvcity.setText("成都");
                    Toast.makeText(demoRadioButton.this, "实打实打算", Toast.LENGTH_SHORT).show();
                }
                if (R.id.rb_shanghai ==i){
                    tvcity.setText("上海");
                }
                if (R.id.rb_chongqing ==i){
                    tvcity.setText("重庆");
                }

            }
        });


    }
}